package edu.mtu.citizenscience.mushroommapper.model;

import com.openswimsoftware.orm.ORM;
import com.openswimsoftware.orm.model.db.DBCreate;

import android.database.sqlite.SQLiteDatabase;
import edu.mtu.citizenscience.mushroommapper.model.family.ModelGenus;
import edu.mtu.citizenscience.mushroommapper.model.family.genus.ModelSpecies;
import edu.mtu.citizenscience.mushroommapper.model.fieldguide.ModelGuideImage;
import edu.mtu.citizenscience.mushroommapper.model.report.ModelImage;
/**
 * @author Corbin Uselton <corbinu@cwuselto@mtu.edu>
 * @copyright (c) 2012 MichiganTech <http://www.mtu.edu>
 * @since 1.0
 * 
 * Create the ORM models in the app DB
 */
public class ModelsCreate implements DBCreate {

	/**
	 * Create the DB models
	 * 
	 * @param   db - SQLiteDatabase - the db reference
	 * @return	void
	 */
	public void onCreate(SQLiteDatabase db) 
	{
		ORM.onCreate(db, ModelReport.class);
		ORM.onCreate(db, ModelImage.class);
		
		ORM.onCreate(db, ModelFamily.class);
		ORM.onCreate(db, ModelGenus.class);
		ORM.onCreate(db, ModelSpecies.class);
		
		ORM.onCreate(db, ModelGuideMushroom.class);
		ORM.onCreate(db, ModelGuideImage.class);
	}

	/**
	 * Upgrade the DB models
	 * 
	 * @param   db - SQLiteDatabase - the db reference
	 * @param   int - oldVer - old db version
	 * @param   int - newVer - new db version
	 * @return	void
	 */
	public void onUpgrade(SQLiteDatabase db, int oldVer, int newVer) 
	{
		ORM.onUpgrade(db, oldVer, newVer, ModelReport.class);
		ORM.onUpgrade(db, oldVer, newVer, ModelImage.class);
		
		ORM.onUpgrade(db, oldVer, newVer, ModelFamily.class);
		ORM.onUpgrade(db, oldVer, newVer, ModelGenus.class);
		ORM.onUpgrade(db, oldVer, newVer, ModelSpecies.class);
		
		ORM.onUpgrade(db, oldVer, newVer, ModelGuideMushroom.class);
		ORM.onUpgrade(db, oldVer, newVer, ModelGuideImage.class);
	}

}
